treedraw <- function(thetree, newdata, factorvar){
	if(factorvar == 0) fakeydata = rep(NA, length = nrow(newdata))
	if(factorvar == 1) fakeydata <- factor(rep(NA, nrow(newdata)), levels =levels(thetree$y))
	
	newdatawhere <- predict.tree(thetree, newdata, "where")
	newtreetable <- table(newdatawhere)
	treenodes <- names(newtreetable)
	oldtreenodes <- names(table(thetree$where))
	
	for(i in 1:length(treenodes)){
		if(is.element(treenodes[i], oldtreenodes)){
			eligibles <- thetree$y[thetree$where == treenodes[i]]}
		else{
			leaves <- as.numeric(row.names(thetree[[1]]))[as.numeric(treenodes[i])]
			temptree <- snip.tree(thetree, floor(leaves/2))
			eligibles <- temptree$y[temptree$where == 
				(1:nrow(temptree[[1]]))[as.numeric(row.names(temptree[[1]]))==floor(leaves/2)]]
		}
		fakeydata[newdatawhere == treenodes[i]] <- bayesianboot(eligibles, newtreetable[i])
	}
	return(fakeydata)
}